package cre.tomcat.ch05.valve;

import org.apache.catalina.Request;
import org.apache.catalina.Response;
import org.apache.catalina.Valve;
import org.apache.catalina.ValveContext;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import java.io.IOException;

/**
 * @Author penglai
 * @Date 2017/1/27.
 */
public class ClientIpLoggerValve implements Valve{
    public String getInfo() {
        return null;
    }

    public void invoke(Request request, Response response, ValveContext valveContext) throws IOException, ServletException {
        valveContext.invokeNext(request, response);

        System.out.println("ClientIpLoggerValve");
        ServletRequest servletRequest = request.getRequest();
        System.out.println(servletRequest.getRemoteAddr());
        System.out.println("---------------------");
    }
}
